struct Container(i32, i32);
// 这个trait检查给定的2个项是否储存于容器中
// 并且能够获得容器的第一个或最后一个值。
trait Contains<A, B> {
    fn contains(&self, _: &A, _: &B) -> bool; //显式要要求`A`和`B`的类型
    fn first(&self) -> i32; //未显式要求`A`和`B`的类型
    fn last(&self) -> i32; //未显式要求`A`和`B`的类型
}
impl Contains<i32, i32> for Container {
//     如果存储的数字和给定的相等则为真
    fn contains(&self, a: &i32, b: &i32) -> bool {
        self.0 == *a && self.1 == *b
    }
    fn first(&self) -> i32 {
        self.0
    }
    fn last(&self) -> i32 {
        self.1
    }
}
// 容器`C` 就包含了`A`和`B`类型。鉴于此，必须指出`A`和`B`显得很麻烦。
fn difference<A, B, C>(container: &C) -> i32 where
    C: Contains<A, B>,{
    container.last() - container.first()
}
fn main() {
    let num_1 = 3;
    let num_2 = 10;
    let container = Container(num_1, num_2);
    println!("Does container contain {} and {}? {}", num_1, num_2, container.contains(&num_1, &num_2));
    println!("First element is: {}", container.first());
    println!("Last element is: {}", container.last());
    println!("The difference is: {}", difference(&container));
}
